/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.tags;

import com.apache.tools.ConfigUtil;
import com.apache.tools.StrUtil;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;

/**
 * description:  获取配置文件变量参数标签
 *
 * @author Hou Dayu 创建时间：2016-8-22
 */
@SuppressWarnings("serial")
public class PortalParamsTag extends TagSupport {

    private String varKey;

    private String varFileName;

    private String sqlQuery;//查询条件

    //private JspWriter writer;

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public int doStartTag() throws JspException {
        boolean b = false;
        try {
            String value = "";
            if (StrUtil.isNull(varFileName)) {
                varFileName = "unity_config";
            }
            value = ConfigUtil.getInstance()
                    .getValueByProperty("config/" + varFileName + ".properties", varKey);
            if (StrUtil.isNotNull(value)) {
                JspWriter writer = this.pageContext.getOut();// 返回一个JspWriter
                writer.print(value);
                b = true;
                writer.flush();
            }
        } catch (IOException e) {
        }
        if (b) {
            return super.EVAL_BODY_INCLUDE;
        } else {
            return super.SKIP_BODY;
        }
    }

    //	public int doEndTag() {
    //		try {
    //			if (null != writer)
    //				writer.close();
    //		} catch (Exception e) {
    //		}
    //		return super.EVAL_BODY_INCLUDE;
    //	}

    public String getVarKey() {
        return varKey;
    }

    public void setVarKey(String varKey) {
        this.varKey = varKey;
    }

    public String getVarFileName() {
        return varFileName;
    }

    public void setVarFileName(String varFileName) {
        this.varFileName = varFileName;
    }

    public String getSqlQuery() {
        return sqlQuery;
    }

    public void setSqlQuery(String sqlQuery) {
        this.sqlQuery = sqlQuery;
    }

}
